package org.lg.dao.impl;

import org.lg.config.Repository;
import org.lg.config.Resource;
import org.lg.dao.ScDao;
import org.lg.entity.Sc;
import org.lg.entity.ScExample;
import org.lg.mapper.ScMapper;
import org.lg.page.PageInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("scDao")
public class ScDaoImpl implements ScDao {
    @Resource
    ScMapper scMapper;


    /**
     * 分页查询选课记录
     * @param pageInfo
     * @return
     */

    public List<Sc> getScBySnoAndByPage(PageInfo pageInfo) throws Exception {
        ScExample scExample = new ScExample();
        String sno = pageInfo.getConditions().get("sno");
        scExample.createCriteria().andSnoEqualTo(sno);
        long l = scMapper.countByExample(scExample);//统计cno等于XX的 选课记录 有多少条
        pageInfo.setItemCount((int)l);
        scExample.setOffset(pageInfo.getOffset());
        scExample.setLimit(pageInfo.getPageSize());
        return scMapper.selectByExampleWithCourse(scExample);
    }



    @Override
    public Sc getScByScno(String scno) throws Exception {
        return scMapper.selectByPrimaryKey(scno);
    }

    @Override
    public List<Sc> getScBySno(String sno) throws Exception {
        ScExample scExample = new ScExample();
        scExample.createCriteria().andSnoEqualTo(sno);

        return scMapper.selectByExampleWithCourse(scExample);
    }



    @Override
    public Integer addSc(Sc sc) throws Exception {
        return scMapper.insertSelective(sc);
    }

    @Override
    public Integer editSc(Sc sc) throws Exception {
        return scMapper.updateByPrimaryKeySelective(sc);
    }


}
